package com.webledger.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBClass {

	private Connection connection;
	private static String connectionString = "jdbc:mysql://192.168.2.100:3306/webleager",
			user = "root", password = "logicall";
	private static DBClass db = new DBClass();

	private DBClass() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {

		}
	}

	public static DBClass getDB() {
		return db;
	}

	public Connection getConnection() {
		try {
			if (connection == null || connection.isClosed()) {
				connection = DriverManager.getConnection(connectionString, user,
						password);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return connection;
	}

	public Connection closeConnection() throws SQLException {

		connection.close();
		return connection;

	}
}
